﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.RestaurantMenu
{
    public class RestaurantMenuPresenter : Presenter<IRestaurantMenuView>
    {
        public RestaurantMenuPresenter(IRestaurantMenuView view)
            : base(view)
        {
        }

        public void Display(string menuId)
        {
            if (menuId == null) return;

            var restaurantMenu = Model.GetRestaurantMenu(menuId);

            View.MenuID = restaurantMenu.MenuID;
            View.MenuCode = restaurantMenu.MenuCode;
            View.MenuName = restaurantMenu.MenuName;
            View.Description = restaurantMenu.Description;
            View.UnitID = restaurantMenu.UnitID;
            View.SalesPrice = restaurantMenu.SalesPrice;
            View.MenuImage = restaurantMenu.MenuImage;
            View.IsActive = restaurantMenu.IsActive;
            View.IsNorm = restaurantMenu.IsNorm;
            View.RestaurantID = restaurantMenu.RestaurantID;
            View.MenuCategoryID = restaurantMenu.MenuCategoryID;
        }

        public void Save()
        {
            var restaurantMenu = new RestaurantMenuModel
            {
                MenuID = View.MenuID,
                MenuCode = View.MenuCode,
                MenuName = View.MenuName,
                Description = View.Description,
                UnitID = View.UnitID,
                SalesPrice = View.SalesPrice,
                MenuImage = View.MenuImage,
                IsActive = View.IsActive,
                IsNorm = View.IsNorm,
                RestaurantID = View.RestaurantID,
                MenuCategoryID = View.MenuCategoryID,
            };

            if (View.MenuID == null)
                Model.AddRestaurantMenu(restaurantMenu);
            else
                Model.UpdateRestaurantMenu(restaurantMenu);
        }

        public int Delete(string menuId)
        {
            return Model.DeleteRestaurantMenu(menuId);
        }
    }
}
